<?php

global $CFG;
require_once($CFG->libdir.'/formslib.php');

class nameaddress_form extends moodleform {

	function definition() {

		$mform    =& $this->_form;

//-------------------------------------------------------------------------------
        // Add General box
//        $mform->addElement('header', 'general', get_string('nameaddress', 'nameaddress', NULL, dirname(__FILE__).'/lang/'));

        // Add name text box
        $mform->addElement('text', 'name', get_string('name', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('name', PARAM_TEXT);
        $mform->addRule('name', null, 'required', null, 'client');

        // Add address1 text box
        $mform->addElement('text', 'address1', get_string('address1', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('address1', PARAM_TEXT);
        $mform->addRule('address1', null, 'required', null, 'client');

        // Add address2 text box
        $mform->addElement('text', 'address2', get_string('address2', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('address2', PARAM_TEXT);

        // Add address3 text box
        $mform->addElement('text', 'address3', get_string('address3', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('address3', PARAM_TEXT);

        // Add town text box
        $mform->addElement('text', 'town', get_string('town', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('town', PARAM_TEXT);
        $mform->addRule('town', null, 'required', null, 'client');

        // Add county text box
        $mform->addElement('text', 'county', get_string('county', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('county', PARAM_TEXT);

        // Add postcode text box
        $mform->addElement('text', 'postcode', get_string('postcode', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), array('size' => 35));
        $mform->setType('postcode', PARAM_TEXT);

        // Add countries dropdown
        $options = array();
        $countries = get_list_of_countries();
        foreach ($countries as $countrynext) {
            $options[$countrynext] = $countrynext;
        }
        $mform->addElement('select', 'country', get_string('country', 'nameaddress', NULL, dirname(__FILE__).'/lang/'), $options);
        $mform->setDefault('country', 'United Kingdom');

        // Add hidden elements
        $mform->addElement('hidden', 'sesskey', sesskey());
        $mform->addElement('hidden', 'id', null);
        $mform->addElement('hidden', 'confirmorder', null);

//-------------------------------------------------------------------------------
        // Add Confirm order button
        $mform->addElement('submit', 'confirmorderbut', get_string('confirmorder', 'nameaddress', NULL, dirname(__FILE__).'/lang/'));
        $mform->closeHeaderBefore('confirmorderbut');
	}
}
?>